<?php     
    $url = new Url();
    $arr_status = LoadConfig::$status;
    $arr_dauso=LoadConfig::$dauso;
    $current_url = Common::getCurrentUrl();
    $path_paging = strpos($current_url,'?') !==false ? $current_url.'&' : $current_url.'?';
    $path_paging = str_replace("?page=".$page."&","?",$path_paging);
    $path_paging = str_replace("&page=".$page."&","&",$path_paging);
    //var_dump($arr_dauso);die;

?>
<div class="main clearfix">
    <div class="box clearfix bottom30">
        <form action="" method="get">
            <div class="title-blue"><h3><strong>SMS KUTE </strong></h3></div>
            <ul class="form4">
                <li class="clearfix">
                    <label><strong>Từ ngày </strong>:</label>
                    <div class="filltext">
                        <?php
                            $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                            'name' => 'from_date',
                            'id' => 'from_date',
                            'value' => $from_date,
                            // additional javascript options for the date picker plugin
                            'options' => array(
                            'showAnim' => 'fold',
                            'dateFormat' => 'dd-mm-yy',
                            'changeYear' => 'true',
                            'changeMonth' => 'true',
                            'showOn' => 'both',
                            'buttonText' => '...'
                            ),
                            'htmlOptions' => array(
                            'style' => 'width:170px',
                            'class' => 'form',
                            ),
                            ));
                        ?>   
                        &nbsp;đến ngày &nbsp; 
                        <?php
                            $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                            'name' => 'to_date',
                            'id' => 'to_date',
                            'value' => $to_date,
                            // additional javascript options for the date picker plugin
                            'options' => array(
                            'showAnim' => 'fold',
                            'dateFormat' => 'dd-mm-yy',
                            'changeYear' => 'true',
                            'changeMonth' => 'true',
                            'showOn' => 'both',
                            'buttonText' => '...'
                            ),
                            'htmlOptions' => array(
                            'style' => 'width:170px',
                            'class' => 'form',
                            ),
                            ));
                        ?> 
                    </div>
                </li>


                <li class="clearfix"><label><strong>Từ khóa</strong>:</label>
                    <div class="filltext">
                        <input name="keyword" type="text" style="width:203px;margin-right:31px;">

                    </div>
                </li>
                <li class="clearfix"><label><strong>Đầu số</strong>:</label>
                    <div class="filltext">
                        <select name="dauso" style="width:203px;margin-right:14px">
                            <option value="2">Tất cả</option>
                            <?php foreach($arr_dauso as $key => $value){ ?>
                                <option value="<?php echo $key;?>" <?php echo ($status == $key ? 'selected="selected"':'' )?>><?php echo $value?></option>
                                <?php }?>
                        </select>

                    </div>

                </li>
                <li class="clearfix"><label><strong>Tình trạng</strong>:</label>
                    <div class="filltext">
                        <select name="status" style="width:203px;margin-right:11px">
                            <option value="2">Tất cả</option>
                            <?php foreach($arr_status as $key => $value){ ?>
                                <option value="<?php echo $key;?>" <?php echo ($status == $key ? 'selected="selected"':'' )?>><?php echo $value?></option>
                                <?php }?>
                        </select>

                    </div>

                </li>
                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext">
                        <input type="submit" class="btn-bigblue" value=" Tìm kiếm"> 
                    </div>
                </li>

            </ul>
        </form>
    </div>
    <div class="box">
        <div class="fillter clearfix">
            <div class="fl">
                <label><strong>Tìm thấy </strong><strong class="clred">&nbsp;<?php echo $count; ?>&nbsp;</strong>kết quả </label>
            </div>
            <div class="fr">
                <ul class="paging">
                    <?php
                        echo Paging::show_paging_cp($max_page,$page,$path_paging);
                    ?>
                </ul>
            </div>
        </div>
        <div class="table clearfix">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr class="bg-grey">
                        <td width="5%">STT</td>
                        <td width="15%"><strong>Tài khoản</strong></td>
                        <td width="15%"><strong>Tiêu đề</strong></td>
                        <td width="20%"><strong>Nội dung sms</strong></td>
                        <td width="5%"><strong>Đầu số</strong></td>
                        <td width="10%"><strong>Tình trạng</strong></td>
                        <td width="5%"><strong>Lượt xem</strong></td>
                        <td width="5%"><strong>Lượt tải</strong></td>
                        <td width="10%"><strong>Thời gian</strong></td>
                        <td width="10%"><strong>Quản trị</strong></td>
                    </tr>
                    <?php foreach($data as $key=>$value) {?>
                        <tr>
                            <td class="middle"><?php echo $value['id']; ?></td>
                            <td class="middle"><?php echo $value['username']; ?></td>
                            <td class="middle"><?php echo $value['title']; ?></td>
                            <td><?php echo $value['content']; ?></td>
                            <td class="middle">
                                <?php switch($value['price']){
                                        case 5000: echo "6522";break;
                                        case 10000: echo "6622";break;
                                        case 15000: echo "6722";break;
                                } ?>
                            </td>
                            <td><input type="checkbox" value="1" id="status_<?php echo $value["id"]?>" <?php echo $value["status"]==1 ? 'checked="checked"':'';?>> Hiển thị</td>
                            <td class="middle"><?php echo $value['hit']; ?></td>
                            <td class="middle"><?php echo $value['download']; ?></td>
                            <td class="middle"><?php echo date("d-m-Y H:i:s",$value["create_date"])?></td>
                            <td class="middle">
                                <a class="s14" onclick="saveRow(<?php echo $value['id']; ?>);" href="javascript:void(0);"> Lưu </a> | 
                                
                                <a onclick="deleteRow(<?php echo $value['id']; ?>);" href="javascript:void(0);">  Xóa  </a> 
                            </td>
                        </tr>
                        <?php } ?>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="fillter clearfix">
            <div class="fr">
                <ul class="paging">
                    <?php
                        echo Paging::show_paging_cp($max_page,$page,$path_paging);
                    ?>
                </ul>
            </div>
        </div>

    </div>
</div>
<script type="">
    function saveRow(id){
    var status = 0;
        if($("#status_"+id).is(":checked")){ status = 1; }
        var strUrl = "<?php echo $url->createUrl("smskute/saveRow") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                status:status,
                id:id
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    location.reload();
                }else{
                    alert(msg);
                }
            }          
        });
    }
    function deleteRow(id){
        var strUrl = "<?php echo $url->createUrl("smskute/deleteRow"); ?>";
        if(confirm('Bạn có chắn chắn muốn xóa không ?')){
            $.ajax({
                type: "POST",
                url: strUrl,
                data: {
                    id:id
                },
                success: function(msg){
                    if(msg == 1){
                        alert('Xóa thành công');
                        location.reload();
                    }else{
                        alert(msg);
                    }
                }          
            });
        }
    }
</script>